package com.jews.example.demo.domain.user;

import com.jews.common.constants.ValidStatus;
import com.jews.jpa.converter.ValidStatusConverter;
import com.jews.jpa.support.BaseJpaAggregate;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

/**
 * 数据库实体对象
 *
 * @author JewsChen
 * @title: User
 * @date 2022/11/29 23:02
 */
@Entity
@Table(name = "admin_user")
@Data
public class User extends BaseJpaAggregate {

    @NotBlank(message = "手机号不能为空")
    private String phone;

    @NotBlank(message = "密码不能为空")
    private String password;

    private String username;

    private Long departmentId;

    @Column(columnDefinition = "text")
    private String extInfo;

    @Convert(converter = ValidStatusConverter.class)
    private ValidStatus validStatus;

    public void init() {
        setValidStatus(ValidStatus.VALID);
    }

    public void valid() {
        setValidStatus(ValidStatus.VALID);
    }

    public void invalid() {
        setValidStatus(ValidStatus.INVALID);
    }
}
